/**
 * Created by sam on 16-11-21.
 */

var dao = require('./dao');
var utils = require('./utils');
var cookie = require('./cookie');
var common = require('../conf/common');


function loadSearchKey(dd,num,ep) {
    var source = common.getSource();
    var url = common.getSearchKeyUrl(utils.replaceAll(dd.key," ","+"));
    utils.getc(url,num,function (d) {
        var s = d.substr(d.indexOf(",[")+3,d.indexOf("],[{")-d.indexOf(",[")-4);
        console.log(d);
        console.log(s);

        var arr = s.split('","');

        for(var s in arr){
            dd.res = arr[s];
            dd.source = source;
            dao.saveSearchKey(dd);
        }

        ep.emit("next");

        console.log(arr);
    });
}

module.exports.loadSearchKey = loadSearchKey;



